<template>
  <div>
    <MyHeader title="购物车案例" color="red" bg="pink"></MyHeader>
    <div class="main">
      <MyGoods v-for="item in list" :key="item.id" :item="item"></MyGoods>
    </div>
    <MyFooter :list="list" @tiedan="allFn"></MyFooter>
  </div>
</template>

<script>
import MyHeader from './components/MyHeader'
import MyGoods from './components/MyGoods'
import MyCount from './components/MyCount'
import MyFooter from './components/MyFooter'
export default {
  data(){
   return {
    list:[]
   }
  },
  components: {
    MyHeader,
    MyGoods,
    MyCount,
    MyFooter,
  },
  created(){
    // console.log(this.$axios)
    this.$axios({
      url:'/api/cart'
    }).then(res=>{
      this.list = res.data.list
    })
  },
  methods: {
    allFn(bool){
      this.list.forEach(obj => obj.goods_state = bool)
      // 把MyFooter内的全选状态true/false同步给所有小选框的关联属性上
    }
  }
}
</script>

<style scoped>
.main {
  padding-top: 45px;
  padding-bottom: 50px;
}
</style>
